﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SPA_Gallery
{
    public partial class View : DotNetNuke.Entities.Modules.PortalModuleBase, IScriptControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DotNetNuke.Framework.ServicesFramework.Instance.RequestAjaxAntiForgerySupport();
            if (!this.IsPostBack) {
                Boolean hasEditPermission =
                   DotNetNuke.Security.Permissions.ModulePermissionController.CanEditModuleContent(this.ModuleConfiguration);
                lnkUploader.Visible = hasEditPermission;
            }

        }

        IEnumerable<ScriptDescriptor> IScriptControl.GetScriptDescriptors()
        {
            ScriptControlDescriptor toReturn = new ScriptControlDescriptor("SPA_Gallery.Gallery", plG.ClientID);

            toReturn.AddProperty("moduleId",this.ModuleId);
            toReturn.AddProperty("clientId", plG.ClientID);
            
            return new List<ScriptDescriptor>(){ toReturn};
        }

        IEnumerable<ScriptReference> IScriptControl.GetScriptReferences()
        {
            List<ScriptReference> toReturn = new List<ScriptReference>();
            toReturn.Add(new ScriptReference("~/desktopmodules/SPA_Gallery/scripts/angular.min.js"));
            toReturn.Add(new ScriptReference("~/desktopmodules/SPA_Gallery/scripts/angular-route.min.js"));
            toReturn.Add(new ScriptReference("~/desktopmodules/SPA_Gallery/js/SPA_Gallery.js"));
            return toReturn;

        }
        protected override void OnPreRender(EventArgs e)
        {
            ScriptManager.GetCurrent(Page).RegisterScriptControl(this);
            base.OnPreRender(e);
        }

        protected override void Render(HtmlTextWriter writer)
        {
            base.Render(writer);
            ScriptManager.GetCurrent(Page).RegisterScriptDescriptors(this);
        }

        /// <summary>
        /// Redirection vers la page d'upload d'images
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lnkUploader_Click(object sender, EventArgs e)
        {
            Boolean hasEditPermission =
                DotNetNuke.Security.Permissions.ModulePermissionController.CanEditModuleContent(this.ModuleConfiguration);

            if (hasEditPermission)
            {
                Response.Redirect(EditUrl("Uploader"));
            }
        }

     



    }
}